package com.cat.math;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-prime-difference/
 * @create 2025/10/13 21:45
 * @since JDK17
 */

public class Solution04 {
    boolean judge(int num) {
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    public int maximumPrimeDifference(int[] nums) {
        int ans = 0, f = -1, n = nums.length;
        for (int i = 0; i < n; i++) {
            if (judge(nums[i])) {
                if (f == -1) {
                    f = i;
                }
                ans = i - f;
            }
        }
        return ans;
    }
}
